package com.css.fxfzaqbz.modules.data.service.impl;

import cn.hutool.core.util.IdUtil;
import com.alibaba.fastjson.JSONObject;
import com.css.fxfzaqbz.base.response.RestResponse;
import com.css.fxfzaqbz.base.upload.controller.AttachmentController;
import com.css.fxfzaqbz.base.upload.entity.AttachmentInfoEntity;
import com.css.fxfzaqbz.base.upload.service.AttachmentInfoService;
import com.css.fxfzaqbz.constants.FxfzConstants;
import com.css.fxfzaqbz.constants.YNEnum;
import com.css.fxfzaqbz.modules.assess.entity.CasualtiesEntity;
import com.css.fxfzaqbz.modules.assess.entity.DisasterAssEntity;
import com.css.fxfzaqbz.modules.assess.entity.RiskAssessmentEntity;
import com.css.fxfzaqbz.modules.assess.entity.SecondDisastersEntity;
import com.css.fxfzaqbz.modules.assess.service.CasualtiesService;
import com.css.fxfzaqbz.modules.assess.service.DisasterService;
import com.css.fxfzaqbz.modules.assess.service.RiskAssessmentService;
import com.css.fxfzaqbz.modules.assess.service.SecondDisastersService;
import com.css.fxfzaqbz.modules.assess1.controller.CustomXWPFDocument;
import com.css.fxfzaqbz.modules.assess1.entity.LittleReport;
import com.css.fxfzaqbz.modules.assess2.entity.Form;
import com.css.fxfzaqbz.modules.assess2.entity.KeyplaceRiskassessment;
import com.css.fxfzaqbz.modules.assess2.entity.UrgencysettleData;
import com.css.fxfzaqbz.modules.assess2.service.KeyplaceRiskassessmentService;
import com.css.fxfzaqbz.modules.assess2.service.UrgencysettleDataService;
import com.css.fxfzaqbz.modules.data.entity.*;
import com.css.fxfzaqbz.modules.data.queryParams.ActMap;
import com.css.fxfzaqbz.modules.data.queryParams.ActReport;
import com.css.fxfzaqbz.modules.data.repository.ExpertRepository;
import com.css.fxfzaqbz.modules.data.repository.ReportRepository;
import com.css.fxfzaqbz.modules.data.repository.ReportTemplateRepository;
import com.css.fxfzaqbz.modules.data.service.ImportantActivityService;
import com.css.fxfzaqbz.modules.data.service.ReportService;
import com.css.fxfzaqbz.modules.data.vo.ExpertVo;
import com.css.fxfzaqbz.modules.data.vo.HistoryReportVo;
import com.css.fxfzaqbz.modules.domain.service.AnalysisService;
import com.css.fxfzaqbz.modules.port.entity.ReportVO;
import com.css.fxfzaqbz.util.*;
import com.css.fxfzaqbz.web.PlatformSessionContext;
import com.css.fxfzaqbz.zcpt.sys.entity.SUser;
import com.css.fxfzaqbz.zcpt.sys.service.SUserService;
import com.css.fxfzaqbz.zcpt.sys.service.SysRoleService;
import lombok.SneakyThrows;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.entity.ContentType;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.util.Units;
import org.apache.poi.xwpf.usermodel.*;
import org.slw.common.helper.PropsHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.io.ClassPathResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;


@Service
public class ReportServiceImpl implements ReportService {

    @Resource
    ReportRepository reportRepository;
    @Resource
    AttachmentInfoService attachmentInfoService;
    @Resource
    SUserService sUserService;
    @Resource
    SysRoleService sysRoleService;
    @Resource
    ReportService reportService;
    @Resource
    ImportantActivityService importantActivityService;
    @Resource
    ExpertRepository expertRepository;
    @Resource
    private RestTemplateUtil restTemplateUtil;


    /*
     * 以下是报告生成
     * */


    @Value("${image.localDir}")
    private String localDir;

    @Resource
    RiskAssessmentService riskAssessmentService;

    @Resource
    CasualtiesService casualtiesService;

    @Resource
    SecondDisastersService secondDisastersService;

    @Resource
    DisasterService disasterService;

    @Resource
    KeyplaceRiskassessmentService keyplaceRiskassessmentService;

    @Resource
    AnalysisService analysisService;

    @Resource
    UrgencysettleDataService urgencysettleDataService;

    @Resource
    AttachmentController attachmentController;


    @SneakyThrows
    @Override
    public Report saveReport(Report report) throws Exception {
        ImportantActivity importantActivity = importantActivityService.getImportantActivityById(report.getIaId());
        String provinceId = importantActivity.getProvinceId();
        String cityId = importantActivity.getCityId();
        String countiesId = importantActivity.getCountiesId();
        String cbshId = importantActivity.getCbshId();
        String bmshId = importantActivity.getBmshId();
        String ldshId = importantActivity.getLdshId();
        Report report1 = reportRepository.getReportByFCI(report);
        if (report1 != null) {
            List<String> strings = new ArrayList<>();
            strings.add(report1.getSrId());
            reportService.delReports(strings);
            String userID = PlatformSessionContext.getUserID();
            report.setCreateUser(userID);
            Timestamp currentTimestamp = PlatformDateUtils.getCurrentTimestamp();
            report.setCreateTime(currentTimestamp);
            report.setSrId(UUIDGenerator.getUUID());
            report.setDelFlag(YNEnum.N.toString());
            report.setSrCreateTime(currentTimestamp);
            AttachmentInfoEntity attach = attachmentInfoService.getAttach(report.getAttachId());
            String attachName = attach.getAttachName();
            report.setSrName(attachName);
            report.setPingStatus("0");
            report.setSrStatus("0");
            report.setProvinceId(provinceId);
            report.setCityId(cityId);
            report.setCountiesId(countiesId);
            report.setCbId(cbshId);
            report.setBmId(bmshId);
            report.setLdId(ldshId);
            report.setCbStatus("0");
            report.setBmStatus("0");
            report.setLdStatus("0");

            //以下是写给产品信息系统的
            String userJson = sUserService.getSUser(userID);
            SUser sUser = CreateGson.createGson().fromJson(userJson, SUser.class);
            //获取创建人单位
            StringBuilder keyword=new StringBuilder();
            if (PlatformObjectUtils.isNotEmpty(importantActivity)){
                keyword.append(importantActivity.getIaName()+",");
                if (PlatformObjectUtils.isNotEmpty(importantActivity.getIaProvince())){
                    keyword.append(importantActivity.getIaProvince());
                }
                if (PlatformObjectUtils.isNotEmpty(importantActivity.getIaCity())){
                    keyword.append(importantActivity.getIaCity());
                }
                if (PlatformObjectUtils.isNotEmpty(importantActivity.getIaCounties())){
                    keyword.append(importantActivity.getIaCounties());
                }
            }
            File filePath = new File(attach.getFileDirId()+attach.getAttachPath());
            //本地文件转为MultipartFile
            MultipartFile file = RemoteTransfer.pathToMultipartFile(filePath);
            String orgName = sUser.getOrgName();
            Properties configGroup = PropsHelper.loadProps("slw-config.properties");
            String cpxxUrl = configGroup.getProperty("cpxxRestTemplateUrl") + "/infAchievement/dockingOtherSystem";
            HttpHeaders headers = new HttpHeaders();
            headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
            headers.set("Authorization", IdUtil.simpleUUID());
            Map<String, String> valueMap = new HashMap<>();
            valueMap.put("dataOrigin", "10");
            valueMap.put("publishingUnit", orgName);
            valueMap.put("createUser", userID);
            valueMap.put("achievementName", attach.getAttachName());
            valueMap.put("keyword", keyword.toString());
            Map<String, MultipartFile> fileParams = new HashMap<>();
            fileParams.put("file", file);
            String res = RemoteTransfer.uploadFile(cpxxUrl, fileParams, valueMap, null);
            return reportRepository.saveReport(report);
        }
        String userID = PlatformSessionContext.getUserID();
        report.setCreateUser(userID);
        Timestamp currentTimestamp = PlatformDateUtils.getCurrentTimestamp();
        report.setCreateTime(currentTimestamp);
        report.setSrId(UUIDGenerator.getUUID());
        report.setDelFlag(YNEnum.N.toString());
        report.setSrCreateTime(currentTimestamp);
        AttachmentInfoEntity attach = attachmentInfoService.getAttach(report.getAttachId());
        String attachName = attach.getAttachName();
        report.setSrName(attachName);
        report.setPingStatus("0");
        report.setSrStatus("0");
        report.setProvinceId(provinceId);
        report.setCityId(cityId);
        report.setCountiesId(countiesId);
        report.setCbId(cbshId);
        report.setBmId(bmshId);
        report.setLdId(ldshId);
        report.setCbStatus("0");
        report.setBmStatus("0");
        report.setLdStatus("0");
        //以下是写给产品信息系统的
        String userJson = sUserService.getSUser(userID);
        SUser sUser = CreateGson.createGson().fromJson(userJson, SUser.class);
        //获取创建人单位
        StringBuilder keyword=new StringBuilder();
        if (PlatformObjectUtils.isNotEmpty(importantActivity)){
            keyword.append(importantActivity.getIaName()+",");
            if (PlatformObjectUtils.isNotEmpty(importantActivity.getIaProvince())){
                keyword.append(importantActivity.getIaProvince());
            }
            if (PlatformObjectUtils.isNotEmpty(importantActivity.getIaCity())){
                keyword.append(importantActivity.getIaCity());
            }
            if (PlatformObjectUtils.isNotEmpty(importantActivity.getIaCounties())){
                keyword.append(importantActivity.getIaCounties());
            }
        }
        File filePath = new File(attach.getFileDirId()+attach.getAttachPath());
        //本地文件转为MultipartFile
        MultipartFile file = RemoteTransfer.pathToMultipartFile(filePath);
        String orgName = sUser.getOrgName();
        Properties configGroup = PropsHelper.loadProps("slw-config.properties");
        String cpxxUrl = configGroup.getProperty("cpxxRestTemplateUrl") + "/infAchievement/dockingOtherSystem";
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON_UTF8);
        headers.set("Authorization", IdUtil.simpleUUID());
        Map<String, String> valueMap = new HashMap<>();
        valueMap.put("dataOrigin", "10");
        valueMap.put("publishingUnit", orgName);
        valueMap.put("createUser", userID);
        valueMap.put("achievementName", attach.getAttachName());
        valueMap.put("keyword", keyword.toString());
        Map<String, MultipartFile> fileParams = new HashMap<>();
        fileParams.put("file", file);
        String res = RemoteTransfer.uploadFile(cpxxUrl, fileParams, valueMap, null);
        return reportRepository.saveReport(report);
    }

    @Override
    public List<Report> getAllReportById(String id) {
        return reportRepository.getAllReportById(id);
    }

    @Override
    public Report getReportById(String id) {
        return reportRepository.getReportById(id);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void delReports(List<String> ids) {
        String userID = PlatformSessionContext.getUserID();
        Timestamp timestamp = PlatformDateUtils.getCurrentTimestamp();
        reportRepository.delReports(ids, timestamp, userID);
    }


    @Override
    public Report updateReport(Report report) {
        report.setUpdateTime(PlatformDateUtils.getCurrentTimestamp());
        return reportRepository.updateReport(report);
    }

    @Override
    public Map<String, Object> getActReport(ActReport actReport) {
        return reportRepository.getActReport(actReport);
    }


    @Override
    public Map<String, Object> getLoginPersonInfo() {
        Map<String, Object> map = new HashMap<>();
        StringBuilder str = new StringBuilder("");
        String userId = PlatformSessionContext.getUserID();
        String user = sUserService.getSUser(userId);
        SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
        map.put("provinceId", sUser.getProvinceId());
        map.put("cityId", sUser.getCityId());
        String role = sysRoleService.getRoleByUserId(userId);
        List<Map> roleMaps = JSONObject.parseArray(role, Map.class);
        for (Map roleMap : roleMaps) {
            str.append(roleMap.get("roleCode") + ",");
        }
        String roles = str.toString();
        if (roles.contains(FxfzConstants.AQBZ_GJJGLY_ROLE)) {
            map.put("isAdmin", true);
        } else {
            map.put("isAdmin", false);
        }
        return map;
    }

    @Override
    public Map<String, Object> getActMap(ActMap actMap) {
        Map<String, Object> map = reportRepository.getActMap(actMap);
        return map;
    }

    @Override
    public String getCode(Report report) {
        String code = reportRepository.getReportByFC(report);
        if (code != null) {
            return code;
        }
        Date startTime = getStartTime();
        Timestamp startTimestamp = new Timestamp(startTime.getTime());
        Date endTime = getEndTime();
        Timestamp endTimestamp = new Timestamp(endTime.getTime());
        String count = reportRepository.getNewCode(report.getIaId(), startTimestamp, endTimestamp);
        if (count == null || count.equals("")) {
            count = "0";
        }
        int i = Integer.parseInt(count);
        i++;
        DecimalFormat dft = new DecimalFormat("000");
        String code1 = dft.format(i); // 格式化为四位流水号 code: 000
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
        String date = sdf.format(new Date());
        String type1 = null;
        if (report.getSrType().equals("地震灾害风险评估报告")) {
            type1 = "PGBG";
        }
        if (report.getSrType().equals("辅助对策报告")) {
            type1 = "DCBG";
        }
        String number = date + type1 + code1;
        return number;

    }

    @Override
    public Report getReportByFC(Report report) {
        return reportRepository.getReportByFCI(report);
    }

    @Override
    public ArrayList<HistoryReportVo> getHistory(Report report) {
        List<Report> reports = reportRepository.getHistory(report.getIaId());
        ArrayList<HistoryReportVo> historyReportVos = new ArrayList<>();
        if (reports != null || reports.size() > 0) {
            for (Report report1 : reports) {
                HistoryReportVo historyReportVo = new HistoryReportVo();
                String createUser = report1.getCreateUser();
                String user = sUserService.getSUser(createUser);
                SUser sUser = CreateGson.createGson().fromJson(user, SUser.class);
                String userName = sUser.getUserName();
                historyReportVo.setUser(userName);
                historyReportVo.setTime(report1.getSrCreateTime());
                historyReportVo.setType(report1.getSrType());
                historyReportVo.setName(report1.getSrName());
                historyReportVo.setAttachId(report1.getAttachId());
                historyReportVos.add(historyReportVo);
            }
        }
        return historyReportVos;

    }

    @Override
    public List<Report> getAllReport(Report report) {
        System.out.println(report.getShStatus());
        List<Report> allReport = reportRepository.getAllReport(report);
        if (allReport == null) {
            return null;
        }
        List<Report> oneReportList = new ArrayList<>();
        List<Report> twoAndThreeReportList = new ArrayList<>();
        String userID = PlatformSessionContext.getUserID();
        if (report.getShStatus().equals("0")) {
            for (Report report1 : allReport) {

                if ((report1.getCbId().equals(userID) && report1.getCbStatus().equals("1")) || (report1.getBmId().equals(userID) && report1.getBmStatus().equals("1")) || (report1.getLdId().equals(userID) && report1.getLdStatus().equals("1"))) {
                    report1.setShStatus("0");
                    oneReportList.add(report1);
                }

            }
            return oneReportList;

        }


        if (report.getShStatus().equals("1")) {
            for (Report report1 : allReport) {
                if ((report1.getCbId().equals(userID) && report1.getCbStatus().equals("2")) || (report1.getBmId().equals(userID) && report1.getBmStatus().equals("2")) || (report1.getLdId().equals(userID) && report1.getLdStatus().equals("2"))) {
                    report1.setShStatus("2");
                    twoAndThreeReportList.add(report1);
                } else if ((report1.getCbId().equals(userID) && report1.getCbStatus().equals("3")) || (report1.getBmId().equals(userID) && report1.getBmStatus().equals("3")) || (report1.getLdId().equals(userID) && report1.getLdStatus().equals("3"))) {
                    report1.setShStatus("3");
                    twoAndThreeReportList.add(report1);
                }

            }
            return twoAndThreeReportList;
        }
        return null;
    }

    @Override
    public Object updateReportStatus(Report report) {
        String userID = PlatformSessionContext.getUserID();
        Report reportById = getReportById(report.getSrId());
        if (userID.equals(reportById.getCbId()) && report.getShStatus().equals("2")) {
            reportById.setCbStatus("2");
            reportById.setCbDate(PlatformDateUtils.getCurrentSqlDate());
            reportById.setBmStatus("1");
            reportById.setMark("0");
        }
        if (userID.equals(reportById.getBmId()) && report.getShStatus().equals("2")) {
            reportById.setBmStatus("2");
            reportById.setBmDate(PlatformDateUtils.getCurrentSqlDate());
            reportById.setLdStatus("1");
            reportById.setMark("1");
        }
        if (userID.equals(reportById.getLdId()) && report.getShStatus().equals("2")) {
            reportById.setLdStatus("2");
            reportById.setLdDate(PlatformDateUtils.getCurrentSqlDate());
            reportById.setSrStatus("2");
            reportById.setMark("2");
            expertRepository.updateStatus("1", reportById.getSrId());
        }


        if (userID.equals(reportById.getCbId()) && report.getShStatus().equals("3")) {
            reportById.setCbStatus("3");
            reportById.setCbDate(PlatformDateUtils.getCurrentSqlDate());
            reportById.setCbReason(report.getReason());
            reportById.setMark("0");
            reportById.setSrStatus("3");
        }
        if (userID.equals(reportById.getBmId()) && report.getShStatus().equals("3")) {
            reportById.setBmStatus("3");
            reportById.setBmDate(PlatformDateUtils.getCurrentSqlDate());
            reportById.setBmReason(report.getReason());
            reportById.setMark("1");
            reportById.setSrStatus("3");
        }
        if (userID.equals(reportById.getLdId()) && report.getShStatus().equals("3")) {
            reportById.setLdStatus("3");
            reportById.setLdDate(PlatformDateUtils.getCurrentSqlDate());
            reportById.setLdReason(report.getReason());
            reportById.setMark("2");
            reportById.setSrStatus("3");
        }

        Report report1 = reportRepository.updateReportStatus(reportById);


        return report1;
    }

    @Override
    public List<ExpertVo> getAllExpert(Report report) {
        List<ExpertVo> expertVoList = expertRepository.getAllExpert(report);
        if (expertVoList == null) {
            return null;
        }

        List<ExpertVo> oneExpertVOList = new ArrayList<>();
        List<ExpertVo> twoAndThreeExpertVOList = new ArrayList<>();
        if (report.getShStatus().equals("0")) {
            for (ExpertVo expertVo : expertVoList) {
                if (expertVo.getStatus().equals("1")) {
                    oneExpertVOList.add(expertVo);
                }
            }
            return oneExpertVOList;
        }
        if (report.getShStatus().equals("1")) {
            for (ExpertVo expertVo : expertVoList) {
                if (expertVo.getStatus().equals("2") || expertVo.getStatus().equals("3")) {
                    twoAndThreeExpertVOList.add(expertVo);
                }
            }
            return twoAndThreeExpertVOList;
        }

        return null;
    }

    @Override
    public void submitSh(String srId) {
        Report report = reportRepository.getReportById(srId);
        String userJson = sUserService.getSUser(PlatformSessionUtils.getUserId());
        SUser sUser = CreateGson.createGson().fromJson(userJson, SUser.class);
        report.setSubmiter(sUser.getUserName());
        report.setSrStatus("1");
        if (report.getCbStatus().equals("0") || report.getCbStatus().equals("3")) {
            report.setCbStatus("1");
        }
        if (report.getBmStatus().equals("3")) {
            report.setBmStatus("1");
        }
        if (report.getLdStatus().equals("3")) {
            report.setLdStatus("1");
        }
        report.setSubmitTime(PlatformDateUtils.getCurrentSqlDate());
        reportRepository.submitSh(report);
    }

    @Override
    public List<String> getAttachIds(String srId) {
        List<Expert> experts = expertRepository.getAllExpertBySrId(srId);
        List<String> attachIds = new ArrayList<>();
        for (Expert expert : experts) {
            String opinion = expert.getOpinion();
            attachIds.add(opinion);
        }
        return attachIds;
    }

    @Override
    public void uploadYiJian(Report report) {

        AttachmentInfoEntity attach = attachmentInfoService.getAttach(report.getPingYijian());
        AttachmentInfoEntity attach1 = attachmentInfoService.getAttach(report.getSrNumber());
        report.setPingYijianName(attach.getAttachName());
        report.setSrName(attach1.getAttachName());
        reportRepository.uploadYiJian(report);
    }

    @Override
    public void reUpload(Report report) {
        AttachmentInfoEntity attach = attachmentInfoService.getAttach(report.getAttachId());
        String attachName = attach.getAttachName();
        report.setSrName(attachName);
        reportRepository.reUpload(report);
    }

    @Override
    public Report getReportByIaId(String id) {
        return reportRepository.getReportByIaId(id);
    }


    /*
     * 生成报告
     * */
    @Override
    public RestResponse createReport(com.css.fxfzaqbz.modules.assess1.vo.ReportVO reportVO, HttpServletResponse response) throws Exception {
        //1 生成报告的逻辑
        String iaId = reportVO.getIaId();
        String id = reportVO.getId();
        //   ImportantActivity importantActivityById = importantActivityService.getImportantActivityById(iaId);
        if (reportVO.getNumber().equals("0")) {
            RestResponse restResponse1 = createReport1(iaId, response,id);
            return restResponse1;
        } else if (reportVO.getNumber().equals("1")) {
            RestResponse restResponse2 = createReport2(iaId, response,id);
            return restResponse2;
        } else {
            RestResponse restResponse3 = createReport3(iaId, response,id);
            return restResponse3;
        }


/*
        ClassPathResource classPathResource = new ClassPathResource("/static/report.docx");
        InputStream input = classPathResource.getInputStream();
        CustomXWPFDocument xwpfDocument = new CustomXWPFDocument(input);
        //根据活动id查询各种信息
       *//* Map reportData = getReportData(iaId);
        createReport(xwpfDocument, reportData, iaId);*//*
        Map reportData = getReportData1(iaId);
        createReport1(xwpfDocument,reportData);
        OutputStream os = null;
        //String fileName = "模板.docx";
        StringBuilder fileName = new StringBuilder();
        String taskName = importantActivityById.getIaName();
        fileName.append("DZZH"+taskName+"_");
        LocalDateTime now = LocalDateTime.now();
        //yyyy-MM-dd-HH:mm:ss
     *//*   SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String format = sdf.format(new Date().getTime());*//*
        String nowFormat = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        fileName.append("(").append(nowFormat).append(").docx");
        os = new FileOutputStream(localDir + File.separator + fileName);
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        xwpfDocument.write(os);
        input.close();
        os.flush();
        os.close();
        File pdfFile = new File(localDir + File.separator + fileName);
        FileInputStream fileInputStream = new FileInputStream(pdfFile);
        MultipartFile multipartFile = new MockMultipartFile(fileName.toString(), fileName.toString(),
                ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
        if (pdfFile.exists()) {
            pdfFile.delete();
        }
        ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
        multipartFiles.add(multipartFile);
        return attachmentController.uploadFile(multipartFiles);*/
    }

    @Resource
    private ReportTemplateRepository reportTemplateRepository;
    /*
    生成第一份报告
    *
    @Override*/
    public RestResponse createReport1(String iaId, HttpServletResponse response,String id) throws Exception {
        //1 生成报告的逻辑
        ImportantActivity importantActivityById = importantActivityService.getImportantActivityById(iaId);
/*
        ClassPathResource classPathResource = new ClassPathResource("/static/地震环境及监测能力分析.docx");
        InputStream input = classPathResource.getInputStream();
*/

        //查询报告模板
         ReportTemplateEntity reportTemplateEntity=reportTemplateRepository.getReportTemplateById(id);
        AttachmentInfoEntity attach = attachmentInfoService.getAttach(reportTemplateEntity.getAttId());
        InputStream input = new FileInputStream(attach.getFileDirId()+attach.getAttachPath());

        CustomXWPFDocument xwpfDocument = new CustomXWPFDocument(input);
        //根据活动id查询各种信息
        Map reportData = getReportData1(iaId);
        createReport1(xwpfDocument, reportData,iaId);
        OutputStream os = null;
        //String fileName = "模板.docx";
        StringBuilder fileName = new StringBuilder();
        String taskName = importantActivityById.getIaName();
        fileName.append(taskName + "_");
        LocalDateTime now = LocalDateTime.now();
        String nowFormat = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        fileName.append("(").append(nowFormat).append(").docx");
        os = new FileOutputStream(localDir + File.separator + fileName);
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        xwpfDocument.write(os);
        input.close();
        os.flush();
        os.close();
        File pdfFile = new File(localDir + File.separator + fileName);
        FileInputStream fileInputStream = new FileInputStream(pdfFile);
        MultipartFile multipartFile = new MockMultipartFile(fileName.toString(), fileName.toString(),
                ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
        if (pdfFile.exists()) {
            pdfFile.delete();
        }
        ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
        multipartFiles.add(multipartFile);
        return attachmentController.uploadFileLittleReport(multipartFiles,iaId,"0");
    }

    private Map getReportData1(String iaId) {
        Map<String, Object> dataMap = new HashMap<>();
        //地震危险性评估-地震构造图
        String dzgztType = "地震构造图";
        List<RiskAssessmentEntity> dzgztList = riskAssessmentService.getRiskByIaIdAndType(iaId, dzgztType);
        List<String> dzgzts = new ArrayList<>();
        if (dzgztList.size() > 0) {
            for (RiskAssessmentEntity riskAssessmentEntity : dzgztList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(riskAssessmentEntity.getSraAssFileId());
                dzgzts.add(riskAssessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
        }
        dataMap.put("dzgzts", dzgzts);

        //地震危险性评估-历史地震分布图
        String lsdzfbt = "历史地震分布图";
        List<RiskAssessmentEntity> lsdzfbtList = riskAssessmentService.getRiskByIaIdAndType(iaId, lsdzfbt);
        List<String> lsdzfbts = new ArrayList<>();
        if (lsdzfbtList.size() > 0) {
            for (RiskAssessmentEntity riskAssessmentEntity : lsdzfbtList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(riskAssessmentEntity.getSraAssFileId());
                lsdzfbts.add(riskAssessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
        }
        dataMap.put("lsdzfbts", lsdzfbts);

        String dzwxxfx = "地震危险性分析";
        List<String> dzwxxfxt = new ArrayList<>();
        List<RiskAssessmentEntity> dzwxxfxList = riskAssessmentService.getRiskByIaIdAndType(iaId, dzwxxfx);
        if (dzwxxfxList.size() > 0) {
            for (RiskAssessmentEntity assessmentEntity : dzwxxfxList) {
                if (assessmentEntity.getSraAssFileId() != null) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(assessmentEntity.getSraAssFileId());
                    dzwxxfxt.add(assessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
                }

            }
        }
        dataMap.put("dzwxxfxt", dzwxxfxt);

        //地震危险性评估-断层分布图（图片）
        String dcfbttp = "断层分布图";
        List<RiskAssessmentEntity> dcfbttpList = riskAssessmentService.getRiskByIaIdAndType(iaId, dcfbttp);
        List<String> dcfbt = new ArrayList<>();
        if (dcfbttpList.size() > 0) {
            for (RiskAssessmentEntity assessmentEntity : dcfbttpList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(assessmentEntity.getSraAssFileId());
                dcfbt.add(assessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
        }
        dataMap.put("dcfbt", dcfbt);
        return dataMap;
    }

    private void createReport1(CustomXWPFDocument doc, Map params,String iaId) throws Exception {
        //替换段落字段和图片
        replaceInPara(doc, params);

        czydDoc(doc, iaId);
    }

    /*
   生成第二份报告
   *
   @Override*/
    public RestResponse createReport2(String iaId, HttpServletResponse response,String id) throws Exception {
        //1 生成报告的逻辑
        ImportantActivity importantActivityById = importantActivityService.getImportantActivityById(iaId);
/*
        ClassPathResource classPathResource = new ClassPathResource("/static/房屋地震灾害分析评估.docx");
        InputStream input = classPathResource.getInputStream();
*/


        //查询报告模板
        ReportTemplateEntity reportTemplateEntity=reportTemplateRepository.getReportTemplateById(id);
        AttachmentInfoEntity attach = attachmentInfoService.getAttach(reportTemplateEntity.getAttId());
        InputStream input = new FileInputStream(attach.getFileDirId()+attach.getAttachPath());


        CustomXWPFDocument xwpfDocument = new CustomXWPFDocument(input);
        //根据活动id查询各种信息
        Map reportData = getReportData2(iaId);
        createReport2(xwpfDocument, reportData, iaId);
        OutputStream os = null;
        //String fileName = "模板.docx";
        StringBuilder fileName = new StringBuilder();
        String taskName = importantActivityById.getIaName();
        fileName.append(taskName + "_");
        LocalDateTime now = LocalDateTime.now();
        String nowFormat = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        fileName.append("(").append(nowFormat).append(").docx");
        os = new FileOutputStream(localDir + File.separator + fileName);
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        xwpfDocument.write(os);
        input.close();
        os.flush();
        os.close();
        File pdfFile = new File(localDir + File.separator + fileName);
        FileInputStream fileInputStream = new FileInputStream(pdfFile);
        MultipartFile multipartFile = new MockMultipartFile(fileName.toString(), fileName.toString(),
                ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
        if (pdfFile.exists()) {
            pdfFile.delete();
        }
        ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
        multipartFiles.add(multipartFile);
        return attachmentController.uploadFileLittleReport(multipartFiles,iaId,"1");
    }

    private Map getReportData2(String iaId) {
        Map<String, Object> dataMap = new HashMap<>();
        //房屋地震灾害风险评估-房屋破坏分布图
        String fwphfbt = "房屋破坏评估";
        //房屋地震灾害风险评估-抗震能力风险初步评估分区图
        String kznlfxcbpgt = "房屋抗震能力评估";

        List<String> kznlfxcbpg = new ArrayList<>();
        List<String> fwph = new ArrayList<>();

        List<DisasterAssEntity> disasterAssEntityList = disasterService.getDisasterAssByIaId(iaId);
        if (disasterAssEntityList.size() > 0) {
            for (DisasterAssEntity disasterAssEntity : disasterAssEntityList) {
                if (disasterAssEntity.getSdaAssSeiIntensity().equals(kznlfxcbpgt)) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(disasterAssEntity.getSdaAssFileId());
                    kznlfxcbpg.add(disasterAssEntity.getSdaAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
                }
                if (disasterAssEntity.getSdaAssSeiIntensity().equals(fwphfbt)) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(disasterAssEntity.getSdaAssFileId());
                    fwph.add(disasterAssEntity.getSdaAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
                }
            }
        }
        dataMap.put("kznlfxcbpg", kznlfxcbpg);
        dataMap.put("fwph", fwph);

        //人口伤亡评估-人口分布图
        String rkfbt = "人口分布图";
        List<String> rkfb = new ArrayList<>();
        List<CasualtiesEntity> rkfbtList = casualtiesService.getCasByIaIdAndType(iaId, rkfbt);
        if (rkfbtList.size() > 0) {
            for (CasualtiesEntity casualtiesEntity : rkfbtList) {
                if (casualtiesEntity.getScFileId() != null) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(casualtiesEntity.getScFileId());
                    rkfb.add(casualtiesEntity.getScFileTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
                }
            }
        }
        dataMap.put("rkfb", rkfb);

        //人口伤亡评估-人员伤亡分布图
        String ryswfbt = "人员伤亡分布图";
        List<String> rysw = new ArrayList<>();
        List<CasualtiesEntity> ryswfbtList = casualtiesService.getCasByIaIdAndType(iaId, ryswfbt);
        if (ryswfbtList.size() > 0) {
            for (CasualtiesEntity casualtiesEntity : ryswfbtList) {
                if (casualtiesEntity.getScFileId() != null) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(casualtiesEntity.getScFileId());
                    rysw.add(casualtiesEntity.getScFileTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
                }
            }
        }
        dataMap.put("rysw", rysw);


        String dzzhfxdjfbt = "地震灾害风险等级分布图";
        List<String> dzzhfxdj = new ArrayList<>();
        List<CasualtiesEntity> dzzhfxdjfbtList = casualtiesService.getCasByIaIdAndType(iaId, dzzhfxdjfbt);
        if (dzzhfxdjfbtList.size() > 0) {
            for (CasualtiesEntity casualtiesEntity : dzzhfxdjfbtList) {
                if (casualtiesEntity.getScFileId() != null) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(casualtiesEntity.getScFileId());
                    dzzhfxdj.add(casualtiesEntity.getScFileTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
                }
            }
        }
        dataMap.put("dzzhfxdj", dzzhfxdj);

        //重点场所风险评估-重点场所风险评估
        String zdcsfxpg = "重点场所风险评估";
        List<String> fxpg = new ArrayList<>();
        List<KeyplaceRiskassessment> keyplaceRiskassessmentList = keyplaceRiskassessmentService.getByIaIdAndContent(iaId, zdcsfxpg);
        if (keyplaceRiskassessmentList.size() > 0) {
            for (KeyplaceRiskassessment keyplaceRiskassessment : keyplaceRiskassessmentList) {
                if (keyplaceRiskassessment.getPictureId() != null) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(keyplaceRiskassessment.getPictureId());
                    fxpg.add(keyplaceRiskassessment.getTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
                }
            }
        }
        dataMap.put("fxpg", fxpg);

        String xjjaz = "需紧急安置人员";
        String xjjTitle="";
        List<UrgencysettleData> urgencysettleDataList = urgencysettleDataService.getUrgencysettleDataByIaIdAndType(iaId, xjjaz);
            if (!PlatformObjectUtils.isEmpty(urgencysettleDataList)){
            xjjTitle = urgencysettleDataList.get(0).getUdTitle();
        }
        dataMap.put("xjjtitle", xjjTitle);


        List<String> dzyjssfzjct = new ArrayList<>();

        String dzygssfzjc = "地震应急疏散辅助决策图";
        List<KeyplaceRiskassessment> keyplaceRiskassessments = keyplaceRiskassessmentService.getByIaIdAndContent(iaId,dzygssfzjc);
        if (keyplaceRiskassessments.size() > 0) {
            for (KeyplaceRiskassessment keyplaceRiskassessment : keyplaceRiskassessments) {
                //辅助分析-地震应急疏散辅助决策图
                    if (keyplaceRiskassessment.getPictureId() != null) {
                        dzyjssfzjct.add(keyplaceRiskassessment.getTitle() + "," + attachmentInfoService.getAttach(keyplaceRiskassessment.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(keyplaceRiskassessment.getPictureId()).getAttachPath());
                    }
            }
        }

        dataMap.put("dzyjssfzjct", dzyjssfzjct);
        return dataMap;
    }

    private void createReport2(CustomXWPFDocument doc, Map params, String iaId) throws Exception {
        //替换段落字段和图片
        replaceInPara(doc, params);
        insertTable2(doc, iaId);
        czydDoc(doc, iaId);
    }

    private void insertTable2(CustomXWPFDocument document, String iaId) throws Exception {
        UrgencysettleData urgencyByIaId = urgencysettleDataService.getUrgencyByIaId(iaId);

        if (urgencyByIaId != null && urgencyByIaId.getUdFileId() != null) {
            List<XWPFTable> tables = document.getTables();
            List<Form> forms = urgencysettleDataService.getExcel(urgencyByIaId.getUdFileId());
            forms.remove(0);
            List<List<String>> lists = new ArrayList<>();
            for (Form form : forms) {
                List<String> list = new ArrayList<>();
                list.add(form.getUdProvince());
                list.add(form.getUdCity());
                list.add(form.getUdCounties());
                list.add(form.getUdPersonnumber());
                lists.add(list);
            }
            WordUtil.insertTable2(tables.get(0), lists);
        }
    }

    /*
   生成第三份报告
   *
   @Override*/
    public RestResponse createReport3(String iaId, HttpServletResponse response,String id) throws Exception {
        //1 生成报告的逻辑
        ImportantActivity importantActivityById = importantActivityService.getImportantActivityById(iaId);
 /*       ClassPathResource classPathResource = new ClassPathResource("/static/地震灾害风险排查及建议.docx");
        InputStream input = classPathResource.getInputStream();
*/


        //查询报告模板
        ReportTemplateEntity reportTemplateEntity=reportTemplateRepository.getReportTemplateById(id);
        AttachmentInfoEntity attach = attachmentInfoService.getAttach(reportTemplateEntity.getAttId());
        InputStream input = new FileInputStream(attach.getFileDirId()+attach.getAttachPath());


        CustomXWPFDocument xwpfDocument = new CustomXWPFDocument(input);
        //根据活动id查询各种信息
        Map reportData = getReportData3(iaId);
        createReport3(xwpfDocument, reportData, iaId);
        OutputStream os = null;
        //String fileName = "模板.docx";
        StringBuilder fileName = new StringBuilder();
        String taskName = importantActivityById.getIaName();
        fileName.append(taskName + "_");
        LocalDateTime now = LocalDateTime.now();
        String nowFormat = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
        fileName.append("(").append(nowFormat).append(").docx");
        os = new FileOutputStream(localDir + File.separator + fileName);
        response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
        xwpfDocument.write(os);
        input.close();
        os.flush();
        os.close();
        File pdfFile = new File(localDir + File.separator + fileName);
        FileInputStream fileInputStream = new FileInputStream(pdfFile);
        MultipartFile multipartFile = new MockMultipartFile(fileName.toString(), fileName.toString(),
                ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
        if (pdfFile.exists()) {
            pdfFile.delete();
        }
        ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
        multipartFiles.add(multipartFile);
        return attachmentController.uploadFileLittleReport(multipartFiles,iaId,"2");
    }

    private Map getReportData3(String iaId) {
        Map<String, Object> dataMap = new HashMap<>();

        //地质灾害统计-按月统计   图
        //地质灾害统计-按区域统计   图
        String dzzhtj = "地质灾害统计";
        String areaImagetitle = "按区域统计柱状图";
        String monthImagetitle = "按月统计柱状图";
        List<String> areaImage = new ArrayList<>();
        List<String> monthImage = new ArrayList<>();
        SecondDisastersEntity secondDisastersByContent = secondDisastersService.getSecondDisastersByContent(dzzhtj, iaId);
        if (secondDisastersByContent != null) {
            if (secondDisastersByContent.getSsdMouseFileId() != null) {
                AttachmentInfoEntity monthAttach = attachmentInfoService.getAttach(secondDisastersByContent.getMonthImage());
                monthImage.add(monthImagetitle + "," + monthAttach.getFileDirId() + monthAttach.getAttachPath());
            }
            if (secondDisastersByContent.getSsdAreaFileId() != null) {
                AttachmentInfoEntity areaAttach = attachmentInfoService.getAttach(secondDisastersByContent.getAreaImage());
                areaImage.add(areaImagetitle + "," + areaAttach.getFileDirId() + areaAttach.getAttachPath());
            }
        }

        dataMap.put("areaImage", areaImage);
        dataMap.put("monthImage", monthImage);

        List<String> wxyfbt = new ArrayList<>();
        List<String> dzzhyhdfbt = new ArrayList<>();
        List<String> wxybrfbt = new ArrayList<>();

        List<SecondDisastersEntity> secondDisastersEntityList = secondDisastersService.getSecondDisastersByIaId(iaId);
        String wxy = "危险源分布图";
        String dzzhyhd = "地震地质灾害隐患点分布图";
        String wxybr = "危险源避让分布图";

        if (secondDisastersEntityList.size() > 0) {
            for (SecondDisastersEntity secondDisastersEntity : secondDisastersEntityList) {
                //次生灾害隐患评估-危险源分布图
                if (secondDisastersEntity.getSsdContent().equals(wxy)) {
                    if (secondDisastersEntity.getSsdImageId() != null) {
                        wxyfbt.add(secondDisastersEntity.getSsdImageTitle() + "," + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getFileDirId() + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getAttachPath());
                    }
                }
                //次生灾害隐患评估-地质灾害隐患点分布图
                if (secondDisastersEntity.getSsdContent().equals(dzzhyhd)) {
                    if (secondDisastersEntity.getSsdImageId() != null) {
                        dzzhyhdfbt.add(secondDisastersEntity.getSsdImageTitle() + "," + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getFileDirId() + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getAttachPath());
                    }
                }
                //次生灾害隐患评估-危险源避让分布图
                if (secondDisastersEntity.getSsdContent().equals(wxybr)) {
                    if (secondDisastersEntity.getSsdImageId() != null) {
                        wxybrfbt.add(secondDisastersEntity.getSsdImageTitle() + "," + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getFileDirId() + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getAttachPath());
                    }
                }
            }
        }
        dataMap.put("wxy", wxyfbt);
        dataMap.put("dzzhyhdfbt", dzzhyhdfbt);
        dataMap.put("wxybrfbt", wxybrfbt);


        List<String> dzygssfzjct = new ArrayList<>();
        List<String> bncsfbt = new ArrayList<>();
        List<String> xxfbt = new ArrayList<>();
        List<String> yyfbt = new ArrayList<>();
        List<String> wzcbdfbt = new ArrayList<>();

        String dzygssfzjc = "地震应急疏散辅助决策图";
        String bncsfb = "避难场所";
        String xxfb = "学校分布图";
        String yyfb = "医院分布图";
        String wzcbdfb = "物资储备库分布图";

        List<AidedAnalyse> aidedAnalyseList = analysisService.getAnalysisByIaId(iaId);
        if (aidedAnalyseList.size() > 0) {
            for (AidedAnalyse aidedAnalyse : aidedAnalyseList) {
                //辅助分析-地震应急疏散辅助决策图
                if (aidedAnalyse.getContent().equals(dzygssfzjc)) {
                    if (aidedAnalyse.getPictureId() != null) {
                        dzygssfzjct.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    }
                }
                //辅助分析-避难场所分布图
                if (aidedAnalyse.getContent().equals(bncsfb)) {
                    if (aidedAnalyse.getPictureId() != null) {
                        bncsfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    }
                }
                //辅助分析-学校分布图
                if (aidedAnalyse.getContent().equals(xxfb)) {
                    if (aidedAnalyse.getPictureId() != null) {
                        xxfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    }
                }
                //辅助分析-医院分布图
                if (aidedAnalyse.getContent().equals(yyfb)) {
                    if (aidedAnalyse.getPictureId() != null) {
                        yyfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    }
                }
                //辅助分析-物资储备点分布图
                if (aidedAnalyse.getContent().equals(wzcbdfb)) {
                    if (aidedAnalyse.getPictureId() != null) {
                        wzcbdfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    }
                }
            }
        }

        dataMap.put("dzyjssfzjct", dzygssfzjct);
        dataMap.put("bncsfbt", bncsfbt);
        dataMap.put("xxfbt", xxfbt);
        dataMap.put("yyfbt", yyfbt);
        dataMap.put("wzcbdfbt", wzcbdfbt);







         /*10.1房屋破坏
        10.2物资储备
        10.3应急疏散
        10.4地震灾害
        10.5其他*/
        String fwphType="房屋破坏";
        String wzcbType="物资储备";
        String yjssType="应急疏散";
        String zzzhType="地震灾害";
        String qtType="其他";
        StringBuilder fwphSb=new StringBuilder();
        StringBuilder wzcbSb=new StringBuilder();
        StringBuilder yjssSb=new StringBuilder();
        StringBuilder dzzhSb=new StringBuilder();
        StringBuilder qtSb=new StringBuilder();

        List<DisposeManager> fwphList=new ArrayList<>();
        List<DisposeManager> wzcbList=new ArrayList<>();
        List<DisposeManager> yjssList=new ArrayList<>();
        List<DisposeManager> zzzhList=new ArrayList<>();
        List<DisposeManager> qtList=new ArrayList<>();
        List<DisposeManager> qcCzByIaId = analysisService.getQcCzByIaId(iaId);


        if (qcCzByIaId.size()>0){
            for (DisposeManager disposeManager : qcCzByIaId) {
                if (disposeManager.getDmType().equals(fwphType)){
                    //房屋破坏
                    fwphList.add(disposeManager);
                }
                if (disposeManager.getDmType().equals(wzcbType)){
                    wzcbList.add(disposeManager);
                  }
                if (disposeManager.getDmType().equals(yjssType)){
                    yjssList.add(disposeManager);
                    }
                if (disposeManager.getDmType().equals(zzzhType)){
                    zzzhList.add(disposeManager);
                  }
                if (disposeManager.getDmType().equals(qtType)){
                    qtList.add(disposeManager);
                }
            }
        }


        List<DisposeManager> fwphList1 = fwphList.stream()
                .collect(Collectors.toMap(DisposeManager::getDmLabel, p -> p, (p1, p2) -> p1))
                .values()
                .stream()
                .collect(Collectors.toList());
        List<DisposeManager> wzcbList1 = wzcbList.stream()
                .collect(Collectors.toMap(DisposeManager::getDmLabel, p -> p, (p1, p2) -> p1))
                .values()
                .stream()
                .collect(Collectors.toList());
        List<DisposeManager> yjssList1 = yjssList.stream()
                .collect(Collectors.toMap(DisposeManager::getDmLabel, p -> p, (p1, p2) -> p1))
                .values()
                .stream()
                .collect(Collectors.toList());
        List<DisposeManager> zzzhList1 = zzzhList.stream()
                .collect(Collectors.toMap(DisposeManager::getDmLabel, p -> p, (p1, p2) -> p1))
                .values()
                .stream()
                .collect(Collectors.toList());
        List<DisposeManager> qtList1 = qtList.stream()
                .collect(Collectors.toMap(DisposeManager::getDmLabel, p -> p, (p1, p2) -> p1))
                .values()
                .stream()
                .collect(Collectors.toList());



        if (!PlatformObjectUtils.isEmpty(fwphList1)){
            for (DisposeManager disposeManager : fwphList1) {
                fwphSb.append("  "+disposeManager.getDmLabel()+"\r\n");
                List<DisposeManager> disposeManagers=analysisService.getAnalysisByFatherLabel(disposeManager.getDmLabel(),iaId,disposeManager.getDmType());
                if (!PlatformObjectUtils.isEmpty(disposeManager)){
                    int i=1;
                    for (DisposeManager manager : disposeManagers) {
                        fwphSb.append("("+i+")"+manager.getDmSubtitle()+"\r\n");
                     //   fwphSb.append("    " + "灾害风险点:" + manager.getDisasterRisk());
                       // fwphSb.append("\r\n"+"    " + "处置要点:" + manager.getDisposalPoint()+"\r\n");
                        fwphSb.append("灾害风险点:" + manager.getDisasterRisk()+"\r\n");
                       fwphSb.append("处置要点:" + manager.getDisposalPoint()+"\r\n");
                        i++;
                    }

                }
                fwphSb.append("\r\n");
            }
        }

        if (!PlatformObjectUtils.isEmpty(wzcbList1)){
            for (DisposeManager disposeManager : wzcbList1) {
                wzcbSb.append("  "+disposeManager.getDmLabel()+"\r\n");
                List<DisposeManager> disposeManagers=analysisService.getAnalysisByFatherLabel(disposeManager.getDmLabel(),iaId,disposeManager.getDmType());
                if (!PlatformObjectUtils.isEmpty(disposeManager)){
                    int i=1;
                    for (DisposeManager manager : disposeManagers) {
                        wzcbSb.append("("+i+")"+manager.getDmSubtitle()+"\r\n");
                        wzcbSb.append("灾害风险点:" + manager.getDisasterRisk()+"\r\n");
                        wzcbSb.append("处置要点:" + manager.getDisposalPoint()+"\r\n");
                        i++;
                    }
                }
                wzcbSb.append("\r\n");
            }
        }
        if (!PlatformObjectUtils.isEmpty(yjssList1)){
            for (DisposeManager disposeManager : yjssList1) {
                yjssSb.append("  "+disposeManager.getDmLabel()+"\r\n");
                List<DisposeManager> disposeManagers=analysisService.getAnalysisByFatherLabel(disposeManager.getDmLabel(),iaId,disposeManager.getDmType());
                if (!PlatformObjectUtils.isEmpty(disposeManager)){
                    int i=1;
                    for (DisposeManager manager : disposeManagers) {
                        yjssSb.append("("+i+")"+manager.getDmSubtitle()+"\r\n");
                        yjssSb.append("灾害风险点:" + manager.getDisasterRisk()+"\r\n");
                        yjssSb.append("处置要点:" + manager.getDisposalPoint()+"\r\n");
                        i++;
                    }
                }
                yjssSb.append("\r\n");
            }
        }
        if (!PlatformObjectUtils.isEmpty(zzzhList1)){
            for (DisposeManager disposeManager : zzzhList1) {
                dzzhSb.append("  "+disposeManager.getDmLabel()+"\r\n");
                List<DisposeManager> disposeManagers=analysisService.getAnalysisByFatherLabel(disposeManager.getDmLabel(),iaId,disposeManager.getDmType());
                if (!PlatformObjectUtils.isEmpty(disposeManager)){
                    int i=1;
                    for (DisposeManager manager : disposeManagers) {
                        dzzhSb.append("("+i+")"+manager.getDmSubtitle()+"\r\n");
                        dzzhSb.append("灾害风险点:" + manager.getDisasterRisk()+"\r\n");
                        dzzhSb.append("处置要点:" + manager.getDisposalPoint()+"\r\n");
                        i++;
                    }
                }
                dzzhSb.append("\r\n");
            }
        }

        if (!PlatformObjectUtils.isEmpty(qtList1)){
            for (DisposeManager disposeManager : qtList1) {
                qtSb.append("  "+disposeManager.getDmLabel()+"\r\n");
                List<DisposeManager> disposeManagers=analysisService.getAnalysisByFatherLabel(disposeManager.getDmLabel(),iaId,disposeManager.getDmType());
                if (!PlatformObjectUtils.isEmpty(disposeManager)){
                    int i=1;
                    for (DisposeManager manager : disposeManagers) {
                        qtSb.append("("+i+")"+manager.getDmSubtitle()+"\r\n");
                        qtSb.append("灾害风险点:" + manager.getDisasterRisk()+"\r\n");
                        qtSb.append("处置要点:" + manager.getDisposalPoint()+"\r\n");
                        i++;
                    }
                }
                qtSb.append("\r\n");
            }
        }

        if (!fwphSb.toString().contains("灾害风险点")){
            fwphSb.append("无。");
        }
        if (!wzcbSb.toString().contains("灾害风险点")){
            wzcbSb.append("无。");
        }
        if (!yjssSb.toString().contains("灾害风险点")){
            yjssSb.append("无。");
        }
        if (!dzzhSb.toString().contains("灾害风险点")){
            dzzhSb.append("无。");
        }
        if (!qtSb.toString().contains("灾害风险点")){
            qtSb.append("无。");
        }

        dataMap.put("fwphSb",fwphSb.toString());
        dataMap.put("wzcbSb",wzcbSb.toString());
        dataMap.put("yjssSb",yjssSb.toString());
        dataMap.put("dzzhSb",dzzhSb.toString());
        dataMap.put("qtSb",qtSb.toString());


        return dataMap;
    }

    private void createReport3(CustomXWPFDocument doc, Map params, String iaId) throws Exception {
        //替换段落字段和图片
        replaceInPara(doc, params);
        insertTable3(doc, iaId);
        czydDoc(doc, iaId);
    }

    private void insertTable3(CustomXWPFDocument document, String iaId) throws Exception {

        String a = "地质灾害统计";
        SecondDisastersEntity secondDisastersByContent = secondDisastersService.getSecondDisastersByContent(a, iaId);
        if (secondDisastersByContent != null) {
            //按月统计文件的ID
            String ssdMouseFileId = secondDisastersByContent.getSsdMouseFileId();
            //按区域统计文件的ID
            String ssdAreaFileId = secondDisastersByContent.getSsdAreaFileId();
            Map<String, Object> excelByMouth = secondDisastersService.getExcelByMouth(ssdMouseFileId);
            List<List> mouthTableList = (List<List>) excelByMouth.get("lists");
            List<List<String>> yList = new ArrayList<>();
            for (List list : mouthTableList) {
                List<String> xlist = new ArrayList<>();
                for (Object s : list) {
                    xlist.add(s + "");
                }
                yList.add(xlist);
            }
            List<XWPFTable> tables = document.getTables();

            WordUtil.insertTable1(tables.get(1), yList);

            Map<String, Object> excelByArea = secondDisastersService.getExcelByArea(ssdAreaFileId);
            List<List> areaTableList = (List<List>) excelByArea.get("lists");
            List<List<String>> qyList = new ArrayList<>();
            for (List list : areaTableList) {
                List<String> xlist = new ArrayList<>();
                for (Object s : list) {
                    xlist.add(s + "");
                }

                qyList.add(xlist);
            }
            WordUtil.insertTable2(tables.get(2), qyList);
        }
    }


    @Override
    public List<ReportVO> getReportPort() {
        return reportRepository.getReportPort();
    }

    @Override
    public RestResponse mergeReport(List<LittleReport> littleReports, HttpServletResponse response) {
        try {
            ClassPathResource classPathResource0 = new ClassPathResource("/static/城市报告-第一章.docx");
            ClassPathResource classPathResource4 = new ClassPathResource("/static/城市报告-第十章.docx");
            InputStream input0 = classPathResource0.getInputStream();
            InputStream input4 = classPathResource4.getInputStream();
            List<InputStream> list=new ArrayList<>();
            list.add(input0);
            InputStream input1=null;
            InputStream input2=null;
            InputStream input3=null;
            ImportantActivity importantActivityById = null;
            for (LittleReport littleReport : littleReports) {
                if (!PlatformObjectUtils.isEmpty(littleReport.getStatus())){
                    importantActivityById = importantActivityService.getImportantActivityById(littleReport.getIaId());
                }
                    if ("0".equals(littleReport.getNumber())&&"1".equals(littleReport.getStatus())){
                        AttachmentInfoEntity attach = attachmentInfoService.getAttach(littleReport.getAttachId());
                        input1=new FileInputStream(attach.getFileDirId()+attach.getAttachPath());
                        list.add(input1);
                   }
                    if ("1".equals(littleReport.getNumber())&&"1".equals(littleReport.getStatus())){
                        AttachmentInfoEntity attach = attachmentInfoService.getAttach(littleReport.getAttachId());
                        input2=new FileInputStream(attach.getFileDirId()+attach.getAttachPath());
                        list.add(input2);
                    }
                    if ("2".equals(littleReport.getNumber())&&"1".equals(littleReport.getStatus())){
                        AttachmentInfoEntity attach = attachmentInfoService.getAttach(littleReport.getAttachId());
                        input3=new FileInputStream(attach.getFileDirId()+attach.getAttachPath());
                        list.add(input3);
                    }

            }
            list.add(input4);
            InputStream input = DocxUtil.mergeDocx(list);
            CustomXWPFDocument document = new CustomXWPFDocument(input);

            if (PlatformObjectUtils.isNotEmpty(importantActivityById)){
                String iaId=importantActivityById.getIaId();
                Map reportData = getReportDataNameAndTime(iaId);
                //替换段落字段和图片
                replaceInPara(document, reportData);
            }




            OutputStream os = null;
            String taskName=null;
            StringBuilder fileName = new StringBuilder();
            taskName = importantActivityById.getIaName();
            fileName.append(taskName + "_");
            LocalDateTime now = LocalDateTime.now();
            String nowFormat = now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd"));
            fileName.append("(").append(nowFormat).append(").docx");
            os = new FileOutputStream(localDir + File.separator + fileName);
            response.setHeader("Content-Disposition", "attachment; filename=" + fileName);
            document.write(os);
            os.flush();
            os.close();
            File pdfFile = new File(localDir + File.separator + fileName);
            FileInputStream fileInputStream = new FileInputStream(pdfFile);
            MultipartFile multipartFile = new MockMultipartFile(fileName.toString(), fileName.toString(),
                    ContentType.APPLICATION_OCTET_STREAM.toString(), fileInputStream);
            if (pdfFile.exists()) {
                pdfFile.delete();
            }
            ArrayList<MultipartFile> multipartFiles = new ArrayList<>();
            multipartFiles.add(multipartFile);

            String iaId=null;
            if (PlatformObjectUtils.isNotEmpty(littleReports.get(0))){
                iaId=littleReports.get(0).getIaId();
            }
            return attachmentController.uploadFileLittleReport(multipartFiles,iaId,"4");
        } catch (Exception ex) {
            ex.printStackTrace();
            return null;
        }
    }

    private Map getReportDataNameAndTime(String iaId) {
        Map<String, Object> dataMap = new HashMap<>();
        ImportantActivity importantActivityById = importantActivityService.getImportantActivityById(iaId);
        //活动名称
        String name = importantActivityById.getIaName();
        dataMap.put("name", name);
        //城市
        String iaCounties = importantActivityById.getIaCounties();
        String city = importantActivityById.getIaCity();
        String iaProvince = importantActivityById.getIaProvince();
        if (city==""||city==null){
            dataMap.put("city", iaProvince);
        }else {
            if (iaCounties==""||iaCounties==null){
                dataMap.put("city", city);
            }else {
                dataMap.put("city", iaCounties);
            }
        }

        //时间 （取到月）
        Date iaStartingTime = importantActivityById.getIaStartingTime();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        String time = df.format(iaStartingTime);
        dataMap.put("time", time);
        return dataMap;
    }


    private void createReport(CustomXWPFDocument doc, Map params, String iaId) throws Exception {
        //替换段落字段和图片
        replaceInPara(doc, params);
        insertTable(doc, iaId);
        //处置要点分析
        czydDoc(doc, iaId);

    }

    private void czydDoc(CustomXWPFDocument doc, String iaId) {

        List<XWPFParagraph> paragraphs = doc.getParagraphs();
        for (XWPFParagraph paragraph : paragraphs) {
            String paragraphText1 = paragraph.getParagraphText();
            if (paragraphText1.contains("期间") || paragraphText1.contains("城市地震灾害风险评估报告")) {
                List<XWPFRun> runs = paragraph.getRuns();
                for (XWPFRun run : runs) {
                    if ("黑体".equals(run.getFontFamily())) {
                        run.setBold(true);
                    }
                }
            }
            if (paragraphText1.contains("地震环境分析") || paragraphText1.contains("地震监测能力分析") || paragraphText1.contains("建筑物抗震能力评估") || paragraphText1.contains("地震灾害风险隐患排查") ||
                    paragraphText1.contains("地震灾害风险防范处置建议") || paragraphText1.contains("地震灾害风险评估总结")) {
                List<XWPFRun> runs = paragraph.getRuns();
                for (XWPFRun run : runs) {
                    String runText = run.toString().trim();
                    if (runText.equals("")) {
                        continue;
                    }
                    if ("黑体".equals(run.getFontFamily())) {
                        run.setFontSize(15);
                        run.setBold(true);
                    }
                }
            }
            if (paragraphText1.contains("image") || paragraphText1.contains("ms")) {
                List<XWPFRun> runs = paragraph.getRuns();
                for (XWPFRun run : runs) {
                    run.setText("", 0);
                }
            }

        }
    }


    private void insertTable(CustomXWPFDocument document, String iaId) throws Exception {

        String a = "地质灾害统计";
        SecondDisastersEntity secondDisastersByContent = secondDisastersService.getSecondDisastersByContent(a, iaId);
        if (secondDisastersByContent!=null){
            //按月统计文件的ID
            String ssdMouseFileId = secondDisastersByContent.getSsdMouseFileId();
            //按区域统计文件的ID
            String ssdAreaFileId = secondDisastersByContent.getSsdAreaFileId();
            Map<String, Object> excelByMouth = secondDisastersService.getExcelByMouth(ssdMouseFileId);
            List<List> mouthTableList = (List<List>) excelByMouth.get("lists");
            List<List<String>> yList = new ArrayList<>();
            for (List list : mouthTableList) {
                List<String> xlist = new ArrayList<>();
                for (Object s : list) {
                    xlist.add(s + "");
                }
                yList.add(xlist);
            }
            List<XWPFTable> tables = document.getTables();

            WordUtil.insertTable1(tables.get(1), yList);

            Map<String, Object> excelByArea = secondDisastersService.getExcelByArea(ssdAreaFileId);
            List<List> areaTableList = (List<List>) excelByArea.get("lists");
            List<List<String>> qyList = new ArrayList<>();
            for (List list : areaTableList) {
                List<String> xlist = new ArrayList<>();
                for (Object s : list) {
                    xlist.add(s + "");
                }

                qyList.add(xlist);
            }
            WordUtil.insertTable2(tables.get(0), qyList);
        }

        UrgencysettleData urgencyByIaId = urgencysettleDataService.getUrgencyByIaId(iaId);

        if (urgencyByIaId!=null&&urgencyByIaId.getUdFileId()!=null){
            List<XWPFTable> tables = document.getTables();
            List<Form> forms = urgencysettleDataService.getExcel(urgencyByIaId.getUdFileId());
            forms.remove(0);
            List<List<String>> lists=new ArrayList<>();
            for (Form form : forms) {
                List<String> list =new ArrayList<>();
                list.add(form.getUdProvince());
                list.add(form.getUdCity());
                list.add(form.getUdCounties());
                list.add(form.getUdPersonnumber());
                lists.add(list);
            }

            WordUtil.insertTable2(tables.get(2), lists);
        }


    }

    private void replaceInPara(CustomXWPFDocument doc, Map params) {
        Iterator<XWPFParagraph> iterator = doc.getParagraphsIterator();
        XWPFParagraph para;
        //center是为了给标题加粗
        int center = 0;
        while (iterator.hasNext()) {
            para = iterator.next();
            para.setWordWrapped(true);
            //行间距
            //para.setSpacingBefore(100);
            center = this.replaceInPara(para, params, doc, center);
        }
    }

    private int replaceInPara(XWPFParagraph para, Map<String, Object> params, CustomXWPFDocument doc, int center) {

        List<XWPFRun> runs;
        Matcher matcher;
        String paragraphText = para.getParagraphText();
        if (this.matcher(para.getParagraphText()).find()) {
            runs = para.getRuns();
            int temp = 0;
            for (int i = 0; i < runs.size(); i++) {
                XWPFRun run = runs.get(i);
                int fontSize = run.getFontSize();
                String fontFamily = run.getFontFamily();
                String runText = run.toString().trim();
                if ("".equals(runText)) {
                    continue;
                }
                if (runText.contains("{") && !runText.contains("}") && runText.length() > 1) {
                    runText = runText + "}";
                }
                if ("{".equals(runText)) {
                    temp = 1;
                }

                if (temp == 1) {
                    if (!"{".equals(runText) && !"}".equals(runText)) {
                        runText = "{" + runText + "}";
                        temp = 0;
                    }
                }
                boolean contains = runText.contains("{");
                if (!runText.contains("{") && !runText.contains("}")) {
                    continue;
                }
                //获取{}中的值
                int firstIndex = runText.indexOf("{");
                int endIndex = runText.indexOf("}");
                int lastIndex = runText.lastIndexOf("}");
                if (firstIndex != -1 && firstIndex + 1 == endIndex) {
                    continue;
                }
                if (endIndex != lastIndex) {
                    //表示存在多个{}
                    //分别获取每一个{}中的值runText
                    List<String> keys = getEveryKey(runText);
                    if (PlatformObjectUtils.isNotEmpty(keys)) {
                        for (String key : keys) {
                            Object o = params.get(key);
                            if (PlatformObjectUtils.isEmpty(o)) {
                                runText = runText.replace("{" + key + "}", "");
                            } else {
                                runText = runText.replace("{" + key + "}", o.toString());
                            }

                        }
                        para.removeRun(i);
                        XWPFRun xwpfRun = para.insertNewRun(i);
                        xwpfRun.setFontSize(fontSize == 22 ? fontSize : 14);
                        xwpfRun.setFontFamily("".equals(fontFamily) ? "Times New Roman" : fontFamily);
                        if (para.getParagraphText().contains("title")){
                            xwpfRun.setFontSize(fontSize);
                            xwpfRun.setFontFamily("".equals(fontFamily) ? "Times New Roman" : fontFamily);
                            xwpfRun.setBold(true);
                        }
                        xwpfRun.setText(runText);
                        break;
                    }
                } else {
                    if (firstIndex > -1 || endIndex > -1) {
                        if (runText.startsWith("{image-")) {
                            runText = runText.replace("{", "").replace("}", "");
                            String[] split = runText.split("-");
                            if (split.length == 2 && StringUtils.isNotBlank(split[1]) && params.containsKey(split[1])) {
                                try {
                                    List<String> imgurls = (List<String>) params.get(split[1]);
                                    int a = 0;
                                    for (String imgurl : imgurls) {
                                        String picType = null;
                                        String[] split1 = imgurl.split(",");
                                        imgurl = split1[1];
                                        if (imgurl.contains(".")) {
                                            picType = imgurl.substring(imgurl.lastIndexOf(".") + 1);
                                        }
                                        InputStream inputStream = new FileInputStream(imgurl);
                                        int width = Units.toEMU(Double.parseDouble("280"));
                                        int height = Units.toEMU(Double.parseDouble("200"));
                                        if (split1[0].equals("按区域统计柱状图")||split1[0].equals("按月统计柱状图")){
                                            width = Units.toEMU(Double.parseDouble("420"));
                                            height = Units.toEMU(Double.parseDouble("300"));
                                        }
                                        run.setText("\t", a);
                                        a = a + 3;
                                        run.addPicture(inputStream, getPictureType(picType), "", width, height);
                                        run.setText("\r\n");
                                        run.setText(split1[0] + "\r\n");
                                        para.setAlignment(ParagraphAlignment.CENTER);
//                                        run.setText("\r\n");
                                        run.setBold(true);
                                    }
                                } catch (IOException | InvalidFormatException e) {

                                }
                            }
                        } else {
                            center++;
                            if ("{".equals(runText) || "}".equals(runText)) {
                                runText = "";
                            } else {
                                String key = runText.substring(firstIndex + 1, endIndex);
                                Object o = params.get(key);
                                if (PlatformObjectUtils.isEmpty(o) || "".equals(o)) {
                                    runText = runText.replace("{" + key + "}", "");
                                } else {
                                    runText = runText.replace("{" + key + "}", o.toString());
                                }
                            }
                            para.removeRun(i);
                            XWPFRun xwpfRun = para.insertNewRun(i);
                            xwpfRun.setFontSize(fontSize == 22 ? fontSize : 14);
                            xwpfRun.setFontFamily(fontFamily);
                            if (center == 1 || center == 2) {
                                xwpfRun.setBold(true);
                            }
                            if (paragraphText.contains("title")){
                                xwpfRun.setFontSize(11);
                                xwpfRun.setFontFamily("宋体");
                                xwpfRun.setBold(true);
                                para.setAlignment(ParagraphAlignment.CENTER);
                            }
                            xwpfRun.setText(runText);
                        }
                        //break;
                    }
                }
            }
        }
        return center;
    }


    private static int getPictureType(String picType) {
        int res = CustomXWPFDocument.PICTURE_TYPE_PICT;
        if (picType != null) {
            if (picType.equalsIgnoreCase("png")) {
                res = CustomXWPFDocument.PICTURE_TYPE_PNG;
            } else if (picType.equalsIgnoreCase("dib")) {
                res = CustomXWPFDocument.PICTURE_TYPE_DIB;
            } else if (picType.equalsIgnoreCase("emf")) {
                res = CustomXWPFDocument.PICTURE_TYPE_EMF;
            } else if (picType.equalsIgnoreCase("jpg") || picType.equalsIgnoreCase("jpeg")) {
                res = CustomXWPFDocument.PICTURE_TYPE_JPEG;
            } else if (picType.equalsIgnoreCase("wmf")) {
                res = CustomXWPFDocument.PICTURE_TYPE_WMF;
            }
        }
        return res;
    }


    private Matcher matcher(String str) {
        Pattern pattern = Pattern.compile("\\{(.+?)\\}", Pattern.CASE_INSENSITIVE);
        Matcher matcher = pattern.matcher(str);
        return matcher;
    }


    private List<String> getEveryKey(String runText) {
        List<Integer> list = new ArrayList<>();
        List<String> keyList = new ArrayList<>();
        char[] chars = runText.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if (chars[i] == '{') {
                list.add(++i);
            }
            if (chars[i] == '}') {
                list.add(i);
            }
        }
        StringBuilder key = new StringBuilder("");
        for (int i = 0; i < list.size(); i++) {
            key.append(runText.substring(list.get(i), list.get(++i)));
            keyList.add(key.toString());
            key = new StringBuilder("");
        }

        return keyList;
    }

    private Map getReportData(String iaId) {
        Map<String, Object> dataMap = new HashMap<>();
        ImportantActivity importantActivityById = importantActivityService.getImportantActivityById(iaId);
        //活动名称
        String name = importantActivityById.getIaName();
        dataMap.put("name", name);
        //城市
        String iaCounties = importantActivityById.getIaCounties();
        String city = importantActivityById.getIaCity();
        String iaProvince = importantActivityById.getIaProvince();
        if (city==""||city==null){
            dataMap.put("city", iaProvince);
        }else {
            if (iaCounties==""||iaCounties==null){
                dataMap.put("city", city);
            }else {
                dataMap.put("city", iaCounties);
            }
        }

        //时间 （取到月）
        Date iaStartingTime = importantActivityById.getIaStartingTime();
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM");
        String time = df.format(iaStartingTime);
        dataMap.put("time", time);


        //地震危险性评估-地震构造图
        String dzgztType = "地震构造图";
        List<RiskAssessmentEntity> dzgztList = riskAssessmentService.getRiskByIaIdAndType(iaId, dzgztType);
        List<String> dzgzts = new ArrayList<>();
        StringBuilder dzgztms = new StringBuilder();
        if (dzgztList.size() > 0) {
            for (RiskAssessmentEntity riskAssessmentEntity : dzgztList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(riskAssessmentEntity.getSraAssFileId());
                dzgzts.add(riskAssessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String sraAssFileDescribe = dzgztList.get(0).getSraAssFileDescribe();
            if (StringUtils.isNotBlank(sraAssFileDescribe)){
                dzgztms = bgDescribeCl(dzgztms, sraAssFileDescribe);
            }

        }

        dataMap.put("dzgzts", dzgzts);
        dataMap.put("msdzgzt", dzgztms.toString());

        //地震危险性评估-历史地震分布图
        String lsdzfbt = "历史地震分布图";
        List<RiskAssessmentEntity> lsdzfbtList = riskAssessmentService.getRiskByIaIdAndType(iaId, lsdzfbt);
        List<String> lsdzfbts = new ArrayList<>();
        StringBuilder lsdzfbtsms = new StringBuilder();
        if (lsdzfbtList.size() > 0) {
            for (RiskAssessmentEntity riskAssessmentEntity : lsdzfbtList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(riskAssessmentEntity.getSraAssFileId());
                lsdzfbts.add(riskAssessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String sraAssFileDescribe = lsdzfbtList.get(0).getSraAssFileDescribe();

            if (StringUtils.isNotBlank(sraAssFileDescribe)){
                lsdzfbtsms = bgDescribeCl(lsdzfbtsms, sraAssFileDescribe);
            }
        }

        dataMap.put("lsdzfbts", lsdzfbts);
        dataMap.put("mslsdzfbts", lsdzfbtsms.toString());


        //地震危险性评估-地震危险性分析（图片）   地震活动趋势分析(图片)
        String dzwxxfxtp = "地震活动趋势分析(图片)";
        List<RiskAssessmentEntity> dzwxxfxtpList = riskAssessmentService.getRiskByIaIdAndType(iaId, dzwxxfxtp);
        List<String> wxxfxtp = new ArrayList<>();
        StringBuilder wxxfxtpms = new StringBuilder();
        if (dzwxxfxtpList.size() > 0) {
            for (RiskAssessmentEntity assessmentEntity : dzwxxfxtpList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(assessmentEntity.getSraAssFileId());
                wxxfxtp.add(assessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String sraAssFileDescribe = dzwxxfxtpList.get(0).getSraAssFileDescribe();
            if (StringUtils.isNotBlank(sraAssFileDescribe)){
                wxxfxtpms = bgDescribeCl(wxxfxtpms, sraAssFileDescribe);
            }
        }
        dataMap.put("wxxfxtp", wxxfxtp);
        dataMap.put("mswxxfxtp", wxxfxtpms.toString());


        String dzwxxfxjl = "地震活动趋势分析";
        List<RiskAssessmentEntity> dzwxxfxjlList = riskAssessmentService.getRiskByIaIdAndType(iaId, dzwxxfxjl);
        StringBuilder sb = new StringBuilder();
        StringBuilder bcms = new StringBuilder();
        if (dzwxxfxjlList.size() > 0) {
            for (RiskAssessmentEntity riskAssessmentEntity : dzwxxfxjlList) {
                for (int i = 1; i < dzwxxfxjlList.size() + 1; i++) {
                    String sraConclusion = riskAssessmentEntity.getSraConclusion();
                    sb.append("    "+sraConclusion);
                    String sraSupDescription = riskAssessmentEntity.getSraSupDescription();
                    bcms.append("    "+sraSupDescription);
                }

            }
        }
        dataMap.put("jielun", sb.toString());
        dataMap.put("bcms", bcms.toString());


        String dzwxxfx = "地震危险性分析";
        List<String> dzwxxfxt = new ArrayList<>();
        StringBuilder dzxwxfxtms = new StringBuilder();
        List<RiskAssessmentEntity> dzwxxfxList = riskAssessmentService.getRiskByIaIdAndType(iaId, dzwxxfx);
        if (dzwxxfxList.size() > 0) {
            for (RiskAssessmentEntity assessmentEntity : dzwxxfxList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(assessmentEntity.getSraAssFileId());
                dzwxxfxt.add(assessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());

            }
            String sraAssFileDescribe = dzwxxfxList.get(0).getSraAssFileDescribe();
            dzxwxfxtms = bgDescribeCl(dzxwxfxtms, sraAssFileDescribe);
        }
        //   dataMap.put("dzwxxfxt", dzwxxfxt);
        //   dataMap.put("dzxwxfxtms", dzxwxfxtms.toString());


        //地震危险性评估-断层分布图（图片）
        String dcfbttp = "断层分布图";
        List<RiskAssessmentEntity> dcfbttpList = riskAssessmentService.getRiskByIaIdAndType(iaId, dcfbttp);
        List<String> dcfbt = new ArrayList<>();
        StringBuilder dcfbtms = new StringBuilder();
        if (dcfbttpList.size() > 0) {
            for (RiskAssessmentEntity assessmentEntity : dcfbttpList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(assessmentEntity.getSraAssFileId());
                dcfbt.add(assessmentEntity.getSraAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());

            }
            String sraAssFileDescribe = dcfbttpList.get(0).getSraAssFileDescribe();


            if (StringUtils.isNotBlank(sraAssFileDescribe)){
                dcfbtms = bgDescribeCl(dcfbtms, sraAssFileDescribe);
            }
        }
        dataMap.put("dcfbt", dcfbt);
        dataMap.put("msdcfbt", dcfbtms.toString());


        //人口伤亡评估-人口分布图
        String rkfbt = "人口分布图";
        List<String> rkfb = new ArrayList<>();
        StringBuilder rkfbms = new StringBuilder();
        List<CasualtiesEntity> rkfbtList = casualtiesService.getCasByIaIdAndType(iaId, rkfbt);
        if (rkfbtList.size() > 0) {
            for (CasualtiesEntity casualtiesEntity : rkfbtList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(casualtiesEntity.getScFileId());
                rkfb.add(casualtiesEntity.getScFileTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String scFileDescribe = rkfbtList.get(0).getScFileDescribe();

            if (StringUtils.isNotBlank(scFileDescribe)){
                rkfbms = bgDescribeCl(rkfbms, scFileDescribe);
            }
        }
        dataMap.put("rkfb", rkfb);
        dataMap.put("msrkfb", rkfbms.toString());


        //人口伤亡评估-人员伤亡分布图
        String ryswfbt = "人员伤亡分布图";
        List<String> rysw = new ArrayList<>();
        StringBuilder ryswms = new StringBuilder();
        List<CasualtiesEntity> ryswfbtList = casualtiesService.getCasByIaIdAndType(iaId, ryswfbt);
        if (ryswfbtList.size() > 0) {
            for (CasualtiesEntity casualtiesEntity : ryswfbtList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(casualtiesEntity.getScFileId());
                rysw.add(casualtiesEntity.getScFileTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String scFileDescribe = ryswfbtList.get(0).getScFileDescribe();

            if (StringUtils.isNotBlank(scFileDescribe)){
                ryswms = bgDescribeCl(ryswms, scFileDescribe);
            }
        }
        dataMap.put("rysw", rysw);
        dataMap.put("msrysw", ryswms.toString());

        String dzzhfxdjfbt = "地震灾害风险等级分布图";
        StringBuilder msdzzhfxdjfbt = new StringBuilder();
        List<String> dzzhfxdj = new ArrayList<>();
        List<CasualtiesEntity> dzzhfxdjfbtList = casualtiesService.getCasByIaIdAndType(iaId, dzzhfxdjfbt);
        if (dzzhfxdjfbtList.size() > 0) {
            for (CasualtiesEntity casualtiesEntity : dzzhfxdjfbtList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(casualtiesEntity.getScFileId());
                dzzhfxdj.add(casualtiesEntity.getScFileTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String scFileDescribe = ryswfbtList.get(0).getScFileDescribe();
            if (StringUtils.isNotBlank(scFileDescribe)){
                msdzzhfxdjfbt = bgDescribeCl(msdzzhfxdjfbt, scFileDescribe);
            }
        }

        dataMap.put("dzzhfxdj", dzzhfxdj);
        dataMap.put("msdzzhfxdjfbt", msdzzhfxdjfbt.toString());


        //房屋地震灾害风险评估-房屋破坏分布图
        String fwphfbt = "房屋破坏评估";
        //房屋地震灾害风险评估-抗震能力风险初步评估分区图
        String kznlfxcbpgt = "房屋抗震能力评估";
        List<String> kznlfxcbpg = new ArrayList<>();
        StringBuilder kznlfxcbpgms = new StringBuilder();

        List<String> fwph = new ArrayList<>();
        StringBuilder fwphms = new StringBuilder();
        List<DisasterAssEntity> disasterAssEntityList = disasterService.getDisasterAssByIaId(iaId);
        if (disasterAssEntityList.size() > 0) {
            String a = "";
            String b = "";
            for (DisasterAssEntity disasterAssEntity : disasterAssEntityList) {
                if (disasterAssEntity.getSdaAssSeiIntensity().equals(kznlfxcbpgt)) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(disasterAssEntity.getSdaAssFileId());
                    kznlfxcbpg.add(disasterAssEntity.getSdaAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
                    a = disasterAssEntity.getSdaAssFileDescribe();
                }
                if (disasterAssEntity.getSdaAssSeiIntensity().equals(fwphfbt)) {
                    AttachmentInfoEntity attach = attachmentInfoService.getAttach(disasterAssEntity.getSdaAssFileId());
                    fwph.add(disasterAssEntity.getSdaAssFileTitel() + "," + attach.getFileDirId() + attach.getAttachPath());
                    b = disasterAssEntity.getSdaAssFileDescribe();
                }
            }
            if (StringUtils.isNotBlank(a)){
                kznlfxcbpgms = bgDescribeCl(kznlfxcbpgms, a);
            }
            if (StringUtils.isNotBlank(b)){
                fwphms = bgDescribeCl(fwphms, b);
            }



        }


        dataMap.put("kznlfxcbpg", kznlfxcbpg);
        dataMap.put("mskznlfxcbpg", kznlfxcbpgms.toString());

        dataMap.put("fwph", fwph);
        dataMap.put("msfwph", fwphms.toString());


        //重点场所风险评估-重点场所风险评估
        String zdcsfxpg = "重点场所风险评估";
        List<String> fxpg = new ArrayList<>();
        StringBuilder fxpgms = new StringBuilder();
        List<KeyplaceRiskassessment> keyplaceRiskassessmentList = keyplaceRiskassessmentService.getByIaIdAndContent(iaId, zdcsfxpg);
        if (keyplaceRiskassessmentList.size() > 0) {
            for (KeyplaceRiskassessment keyplaceRiskassessment : keyplaceRiskassessmentList) {
                AttachmentInfoEntity attach = attachmentInfoService.getAttach(keyplaceRiskassessment.getPictureId());
                fxpg.add(keyplaceRiskassessment.getTitle() + "," + attach.getFileDirId() + attach.getAttachPath());
            }
            String description = keyplaceRiskassessmentList.get(0).getDescription();
            if (StringUtils.isNotBlank(description)){
                fxpgms = bgDescribeCla(fxpgms, description);
            }
        }
        dataMap.put("fxpg", fxpg);
        dataMap.put("msfxpg", fxpgms.toString());


        //地质灾害统计-按月统计   图
        //地质灾害统计-按区域统计   图
        String dzzhtj = "地质灾害统计";
        String monthTitle="";
        String areaTitle="";
        String areaImagetitle="按区域统计柱状图";
        String monthImagetitle="按月统计柱状图";
        List<String> areaImage = new ArrayList<>();
        List<String> monthImage = new ArrayList<>();
        SecondDisastersEntity secondDisastersByContent = secondDisastersService.getSecondDisastersByContent(dzzhtj, iaId);
        if (secondDisastersByContent!=null){
            monthTitle = secondDisastersByContent.getSsdMonthTitle();
            areaTitle=secondDisastersByContent.getSsdAreaTitle();
            AttachmentInfoEntity areaAttach = attachmentInfoService.getAttach(secondDisastersByContent.getAreaImage());
            AttachmentInfoEntity monthAttach = attachmentInfoService.getAttach(secondDisastersByContent.getMonthImage());
            areaImage.add(areaImagetitle+","+areaAttach.getFileDirId() + areaAttach.getAttachPath());
            monthImage.add(monthImagetitle+","+monthAttach.getFileDirId() + monthAttach.getAttachPath());
        }

        dataMap.put("monthtitle", monthTitle);
        dataMap.put("areatitle", areaTitle);


    /*    dataMap.put("areaImagetitle", areaImagetitle);
        dataMap.put("monthImagetitle", monthImagetitle);*/
        dataMap.put("areaImage", areaImage);
        dataMap.put("monthImage", monthImage);


        List<String> dzygssfzjct = new ArrayList<>();
        List<String> bncsfbt = new ArrayList<>();
        List<String> xxfbt = new ArrayList<>();
        List<String> yyfbt = new ArrayList<>();
        List<String> wzcbdfbt = new ArrayList<>();


        StringBuilder dzygssfzjctms = new StringBuilder();
        StringBuilder bncsfbtms = new StringBuilder();
        StringBuilder xxfbtms = new StringBuilder();
        StringBuilder yyfbtms = new StringBuilder();
        StringBuilder wzcbdfbtms = new StringBuilder();

        String dzygssfzjc = "地震应急疏散辅助决策图";
        String bncsfb = "避难场所";
        String xxfb = "学校分布图";
        String yyfb = "医院分布图";
        String wzcbdfb = "物资储备库分布图";

        List<AidedAnalyse> aidedAnalyseList = analysisService.getAnalysisByIaId(iaId);
        if (aidedAnalyseList.size() > 0) {
            String a = "";
            String b = "";
            String c = "";
            String d = "";
            String e = "";
            for (AidedAnalyse aidedAnalyse : aidedAnalyseList) {
                //辅助分析-地震应急疏散辅助决策图
                if (aidedAnalyse.getContent().equals(dzygssfzjc)) {
                    dzygssfzjct.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    a = aidedAnalyse.getDescription();
                }
                //辅助分析-避难场所分布图
                if (aidedAnalyse.getContent().equals(bncsfb)) {
                    bncsfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    b = aidedAnalyse.getDescription();
                }
                //辅助分析-学校分布图
                if (aidedAnalyse.getContent().equals(xxfb)) {
                    xxfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    c = aidedAnalyse.getDescription();
                }
                //辅助分析-医院分布图
                if (aidedAnalyse.getContent().equals(yyfb)) {
                    yyfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    d = aidedAnalyse.getDescription();
                }
                //辅助分析-物资储备点分布图
                if (aidedAnalyse.getContent().equals(wzcbdfb)) {
                    wzcbdfbt.add(aidedAnalyse.getTitle() + "," + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getFileDirId() + attachmentInfoService.getAttach(aidedAnalyse.getPictureId()).getAttachPath());
                    e = aidedAnalyse.getDescription();
                }
            }

            if (StringUtils.isNotBlank(a)){
                dzygssfzjctms = bgDescribeCla(dzygssfzjctms, a);
            }
            if (StringUtils.isNotBlank(b)){
                bncsfbtms = bgDescribeCla(bncsfbtms, b);
            }
            if (StringUtils.isNotBlank(c)){
                xxfbtms = bgDescribeCla(xxfbtms, c);
            }
            if (StringUtils.isNotBlank(d)){
                yyfbtms = bgDescribeCla(yyfbtms, d);
            }
            if (StringUtils.isNotBlank(e)){
                wzcbdfbtms = bgDescribeCla(wzcbdfbtms, e);
            }
        }

        dataMap.put("dzyjssfzjct", dzygssfzjct);
        dataMap.put("msdzyjssfzjct", dzygssfzjctms.toString());

        dataMap.put("bncsfbt", bncsfbt);
        dataMap.put("msbncsfbt", bncsfbtms.toString());

        dataMap.put("xxfbt", xxfbt);
        dataMap.put("msxxfbt", xxfbtms.toString());

        dataMap.put("yyfbt", yyfbt);
        dataMap.put("msyyfbt", yyfbtms.toString());

        dataMap.put("wzcbdfbt", wzcbdfbt);
        dataMap.put("mswzcbdfbt", wzcbdfbtms.toString());


        List<String> wxyfbt = new ArrayList<>();
        List<String> dzzhyhdfbt = new ArrayList<>();
        List<String> wxybrfbt = new ArrayList<>();

        StringBuilder wxyfbtms = new StringBuilder();
        StringBuilder dzzhyhdfbtms = new StringBuilder();
        StringBuilder wxybrfbtms = new StringBuilder();

        List<SecondDisastersEntity> secondDisastersEntityList = secondDisastersService.getSecondDisastersByIaId(iaId);
        String wxy = "危险源分布图";
        String dzzhyhd = "地震地质灾害隐患点分布图";
        String wxybr = "危险源避让分布图";

        if (secondDisastersEntityList.size() > 0) {
            String b = "";
            String c = "";
            String d = "";
            for (SecondDisastersEntity secondDisastersEntity : secondDisastersEntityList) {
                //次生灾害隐患评估-危险源分布图
                if (secondDisastersEntity.getSsdContent().equals(wxy)) {
                    wxyfbt.add(secondDisastersEntity.getSsdImageTitle() + "," + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getFileDirId() + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getAttachPath());
                    b = secondDisastersEntity.getSsdDescribe();
                }
                //次生灾害隐患评估-地质灾害隐患点分布图
                if (secondDisastersEntity.getSsdContent().equals(dzzhyhd)) {
                    dzzhyhdfbt.add(secondDisastersEntity.getSsdImageTitle() + "," + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getFileDirId() + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getAttachPath());
                    c = secondDisastersEntity.getSsdDescribe();
                }
                //次生灾害隐患评估-危险源避让分布图
                if (secondDisastersEntity.getSsdContent().equals(wxybr)) {
                    wxybrfbt.add(secondDisastersEntity.getSsdImageTitle() + "," + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getFileDirId() + attachmentInfoService.getAttach(secondDisastersEntity.getSsdImageId()).getAttachPath());
                    d = secondDisastersEntity.getSsdDescribe();
                }
            }

            if (StringUtils.isNotBlank(b)){
                wxyfbtms = bgDescribeCl(wxyfbtms, b);
            }
            if (StringUtils.isNotBlank(c)){
                dzzhyhdfbtms = bgDescribeCl(dzzhyhdfbtms, c);
            }
            if (StringUtils.isNotBlank(d)){
                wxybrfbtms = bgDescribeCl(wxybrfbtms, d);
            }
        }

        dataMap.put("wxy", wxyfbt);
        dataMap.put("mswxyfbt", wxyfbtms.toString());

        dataMap.put("dzzhyhdfbt", dzzhyhdfbt);
        dataMap.put("msdzzhyhdfbt", dzzhyhdfbtms.toString());

        dataMap.put("wxybrfbt", wxybrfbt);
        dataMap.put("mswxybrfbt", wxybrfbtms.toString());

        List<String> xjjazry = new ArrayList<>();
        String xjjaz = "需紧急安置人员";
        StringBuilder msxjjazry = new StringBuilder();
        String xjjTitle="";
        List<UrgencysettleData> urgencysettleDataList = urgencysettleDataService.getUrgencysettleDataByIaIdAndType(iaId, xjjaz);
        if (urgencysettleDataList.size() > 0) {
            for (UrgencysettleData urgencysettleData : urgencysettleDataList) {
                xjjazry.add(urgencysettleData.getUdTitle() + "," + attachmentInfoService.getAttach(urgencysettleData.getUdFileId()).getFileDirId() + attachmentInfoService.getAttach(urgencysettleData.getUdFileId()).getAttachPath());
            }
           xjjTitle = urgencysettleDataList.get(0).getUdTitle();
            if (StringUtils.isNotBlank(urgencysettleDataList.get(0).getUdDescription())){
                String udDescription = urgencysettleDataList.get(0).getUdDescription();
                msxjjazry = bgDescribeCl(msxjjazry, udDescription);
            }


        }

        //  dataMap.put("xjjazry", xjjazry);

        dataMap.put("msxjjazry", msxjjazry.toString());
        dataMap.put("xjjtitle", xjjTitle);


        /*10.1房屋破坏
        10.2物资储备
        10.3应急疏散
        10.4地震灾害
        10.5其他*/
        String fwphType="房屋破坏";
        String wzcbType="物资储备";
        String yjssType="应急疏散";
        String zzzhType="地震灾害";
        String qtType="其他";
        StringBuilder fwphSb=new StringBuilder();
        StringBuilder wzcbSb=new StringBuilder();
        StringBuilder yjssSb=new StringBuilder();
        StringBuilder dzzhSb=new StringBuilder();
        StringBuilder qtSb=new StringBuilder();
        List<DisposeManager> qcCzByIaId = analysisService.getQcCzByIaId(iaId);
        if (qcCzByIaId.size()>0){
            fwphSb.append("  ");
            wzcbSb.append("  ");
            yjssSb.append("  ");
            dzzhSb.append("  ");
            qtSb.append("  ");

            for (DisposeManager disposeManager : qcCzByIaId) {
                if (disposeManager.getDmType().equals(fwphType)){
                    fwphSb.append("    " + "灾害风险点:" + disposeManager.getDisasterRisk());
                    fwphSb.append("\r\n"+"    " + "处置要点:" + disposeManager.getDisposalPoint()+"\r\n");
                }
                if (disposeManager.getDmType().equals(wzcbType)){
                    wzcbSb.append("    " + "灾害风险点:" + disposeManager.getDisasterRisk());
                    wzcbSb.append("\r\n" + "    " + "处置要点:" + disposeManager.getDisposalPoint()+"\r\n");
                }
                if (disposeManager.getDmType().equals(yjssType)){
                    yjssSb.append("    " + "灾害风险点:" + disposeManager.getDisasterRisk());
                    yjssSb.append("\r\n"+"    " + "处置要点:" + disposeManager.getDisposalPoint()+"\r\n");
                }
                if (disposeManager.getDmType().equals(zzzhType)){
                    dzzhSb.append("    " + "灾害风险点:" + disposeManager.getDisasterRisk());
                    dzzhSb.append("\r\n"+"    " + "处置要点:" + disposeManager.getDisposalPoint()+"\r\n");
                }
                if (disposeManager.getDmType().equals(qtType)){
                    qtSb.append("    " + "灾害风险点:" + disposeManager.getDisasterRisk());
                    qtSb.append("\r\n"+"    " + "处置要点:" + disposeManager.getDisposalPoint()+"\r\n");
                }
            }
        }
        if (!fwphSb.toString().contains("灾害风险点")){
            fwphSb.append("无。");
        }
        if (!wzcbSb.toString().contains("灾害风险点")){
            wzcbSb.append("无。");
        }
        if (!yjssSb.toString().contains("灾害风险点")){
            yjssSb.append("无。");
        }
        if (!dzzhSb.toString().contains("灾害风险点")){
            dzzhSb.append("无。");
        }
        if (!qtSb.toString().contains("灾害风险点")){
            qtSb.append("无。");
        }
        dataMap.put("fwphSb",fwphSb.toString());
        dataMap.put("wzcbSb",wzcbSb.toString());
        dataMap.put("yjssSb",yjssSb.toString());
        dataMap.put("dzzhSb",dzzhSb.toString());
        dataMap.put("qtSb",qtSb.toString());
        return dataMap;
    }

    private StringBuilder bgDescribeCla(StringBuilder a, String Describe) {
        String[] split = Describe.split("&&");
        a.append("  ");
        for (int i = 0; i < split.length; i++) {
            a.append("  ");
            a.append(split[i]);
            a.append("\r\n");
        }
        return a;
    }


    //报告描述处理的方法
    private StringBuilder bgDescribeCl(StringBuilder a, String Describe) {
        String[] split = Describe.split("@@@");
        a.append("  ");
        for (int i = 0; i < split.length; i++) {
            a.append("  ");
            a.append(split[i]);
            a.append("\r\n");
        }
        return a;
    }


    private Date getStartTime() {
        Calendar todayStart = Calendar.getInstance();
        todayStart.set(Calendar.SECOND, 0);
        todayStart.set(Calendar.MINUTE, 0);
        todayStart.set(Calendar.HOUR_OF_DAY, 0);
        todayStart.set(Calendar.MILLISECOND, 0);
        return todayStart.getTime();
    }

    private Date getEndTime() {
        Calendar todayEnd = Calendar.getInstance();
        todayEnd.set(Calendar.SECOND, 59);
        todayEnd.set(Calendar.MINUTE, 59);
        todayEnd.set(Calendar.HOUR_OF_DAY, 23);
        todayEnd.set(Calendar.MILLISECOND, 999);
        return todayEnd.getTime();
    }




}
